from apscheduler.executors.pool import ProcessPoolExecutor
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore


def os_sqlite_path():
    from pathlib import Path

    db_path = Path(__file__).parent / "jobs.sqlite3"
    return "sqlite:///" + str(db_path)


class SchedulerSettings(object):
    JOBSTORES = {"default": SQLAlchemyJobStore(url=os_sqlite_path())}

    EXECUTORS = {
        "default": {"type": "threadpool", "max_workers": 20},
        "processpool": ProcessPoolExecutor(max_workers=5),
    }

    JOB_DEFAULTS = {"coalesce": False, "max_instances": 3}

    def dict(self):
        return {
            "jobstores": self.JOBSTORES,
            "executors": self.EXECUTORS,
            "job_defaults": self.JOB_DEFAULTS,
        }


settings = SchedulerSettings()
